import Vue from 'vue'
import Router from 'vue-router'
import login from '../views/auth/login'
// import {getLocalStorage} from '../utils/localStorage'
import home from '../views/home'
import listhost from '../views/host/listhost'
import listips from '../views/ips/listips'
import minions from '../views/salt/minions'
import listsalt from '../views/salt/listsalt'
import listreturns from '../views/salt/listreturns'
import listservice from '../views/service/listservice'
import listproject from '../views/project/listproject'
import listPubProject from '../views/publish/listPubProject'
import projectReport from '../views/report/project_report'
import departmentReport from '../views/report/department_report'
import publishReport from '../views/report/publish_report'
import dashboard from '../views/dashboard/dashboard'
import error from '../views/error/error'
import listbuild from '../views/publish/listbuild'
import listPublish from '../views/publish/listPublish'
import todayPublish from '../views/publish/todayPublish'
import nginx from '../views/marketplace/nginx'

Vue.use(Router)

const router = new Router({
  routes: [
    { name: 'login', path: '/login', component: login },
    { name: 'error', path: '/error', component: error },
    { name: 'home',
      path: '/',
      component: home,
      // meta: {
      //   requireAuth: true
      // },
      children: [
        { path: 'nginx', name: 'nginx', component: nginx },
        { path: 'dashboard', name: 'dashboard', component: dashboard, meta: { requireAuth: true } },
        { path: 'listhost', name: 'listhost', component: listhost, meta: { requireAuth: true } },
        { path: 'listips', name: 'listips', component: listips, meta: { requireAuth: true } },
        { path: 'minions', name: 'minions', component: minions, meta: { requireAuth: true } },
        { path: 'listsalt', name: 'listsalt', component: listsalt, meta: { requireAuth: true } },
        { path: 'listreturns', name: 'listreturns', component: listreturns, meta: { requireAuth: true } },
        { path: 'listservice', name: 'listservice', component: listservice, meta: { requireAuth: true } },
        { path: 'listproject', name: 'listproject', component: listproject, meta: { requireAuth: true } },
        { path: 'listPubProject', name: 'listPubProject', component: listPubProject, meta: { requireAuth: true } },
        { path: 'project_report', name: 'project_report', component: projectReport, meta: { requireAuth: true } },
        { path: 'department_report', name: 'department_report', component: departmentReport, meta: { requireAuth: true } },
        { path: 'publish_report', name: 'publish_report', component: publishReport, meta: { requireAuth: true } },
        { path: '/listbuild/:projectId', name: 'listbuild', component: listbuild, meta: { requireAuth: true } },
        { path: '/listPublish/:projectId', name: 'listPublish', component: listPublish, meta: { requireAuth: true } },
        { path: 'todayPublish', name: 'todayPublish', component: todayPublish, meta: { requireAuth: true } }
      ]
    }
  ]
})

// router.beforeEach((to, from, next) => {
//   if (to.meta.requireAuth) {
//     if (getLocalStorage('admin-token')) {
//       next()
//     } else {
//       next({
//         path: 'login',
//         query: {redirect: to.fullPath}
//       })
//     }
//   } else {
//     next()
//   }
// })

export default router
